***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\googletrends\googletrends.dta", clear

***prepare outcomes

gen rev_avg_Creat = avg_Creat*-1
gen rev_avg_ID = avg_ID*-1
egen avg_avggoogle=rowmean(avg_Evo avg_Etheory avg_Eprocess avg_Darwin avg_Nselection rev_avg_Creat rev_avg_ID)
egen avg_avggoogle2=rowmean(avg_Evo avg_Etheory avg_Eprocess avg_Darwin avg_Nselection avg_Creat avg_ID)

***prepare treatments

gen evolution_score=.
replace evolution_score= 9 if state==1 & year<2005
replace evolution_score= 21 if state==1 & year>=2005
replace evolution_score= 48 if state==2 & year<2006
replace evolution_score= 59 if state==2 & year>=2006
replace evolution_score= 82 if state==4 & year<2005
replace evolution_score= 82 if state==4 & year>=2005
replace evolution_score= 55 if state==5 & year<2005
replace evolution_score= 66 if state==5 & year>=2005
replace evolution_score= 100 if state==6
replace evolution_score= 86 if state==8 & year<2009
replace evolution_score= 82 if state==8 & year>=2009
replace evolution_score= 100 if state==9 & year<2004
replace evolution_score= 59 if state==9 & year>=2004
replace evolution_score= 91 if state==10 & year<2006
replace evolution_score= 80 if state==10 & year>=2006
replace evolution_score= 80 if state==11 & year<2006
replace evolution_score= 96 if state==11 & year>=2006
replace evolution_score= 16 if state==12 & year<2008
replace evolution_score= 91 if state==12 & year>=2008
replace evolution_score= 7 if state==13 & year<2004
replace evolution_score= 66 if state==13 & year>=2004
replace evolution_score= 91 if state==15 & year<2005
replace evolution_score= 75 if state==15 & year>=2005
replace evolution_score= 82 if state==16 & year<2007
replace evolution_score= 82 if state==16 & year>=2007
replace evolution_score= 45 if state==17 & year<2004
replace evolution_score= 82 if state==17 & year>=2004
replace evolution_score= 100 if state==18 & year<2006
replace evolution_score= 96 if state==18 & year>=2006
replace evolution_score= 77 if state==19 & year>=2007
replace evolution_score= 0 if state==20 & year<2007
replace evolution_score= 96 if state==20 & year>=2007
replace evolution_score= 55 if state==21 & year<2006
replace evolution_score= 55 if state==21 & year>=2006
replace evolution_score= 64 if state==22 & year<2005
replace evolution_score= 27 if state==22 & year>=2005
replace evolution_score= 30 if state==23 & year<2007
replace evolution_score= 68 if state==23 & year>=2007
replace evolution_score= 77 if state==24 & year<2002
replace evolution_score= 73 if state==24 & year>=2002
replace evolution_score= 82 if state==25 & year<2006
replace evolution_score= 84 if state==25 & year>=2006
replace evolution_score= 84 if state==26 & year<2000
replace evolution_score= 80 if state==26 & year>=2000
replace evolution_score= 86 if state==27 & year<2009
replace evolution_score= 89 if state==27 & year>=2009
replace evolution_score= 5 if state==28 & year<2008
replace evolution_score= 86 if state==28 & year>=2008
replace evolution_score= 82 if state==29 & year<2008
replace evolution_score= 78 if state==29 & year>=2008
replace evolution_score= 82 if state==30 & year<2006
replace evolution_score= 75 if state==30 & year>=2006
replace evolution_score= 66 if state==31 
replace evolution_score= 70 if state==32 & year<2004
replace evolution_score= 77 if state==32 & year>=2004
replace evolution_score= 23 if state==33 & year<2006
replace evolution_score= 91 if state==33 & year>=2006
replace evolution_score= 100 if state==34 & year<2002
replace evolution_score= 100 if state==34 & year>=2002
replace evolution_score= 73 if state==35 & year<2003
replace evolution_score= 91 if state==35 & year>=2003
replace evolution_score= 68 if state==36 
replace evolution_score= 100 if state==37 & year<2004
replace evolution_score= 82 if state==37 & year>=2004
replace evolution_score= 9 if state==38 & year<2006
replace evolution_score= 64 if state==38 & year>=2006
replace evolution_score= 30 if state==39 & year<2006
replace evolution_score= 86 if state==39 & year>=2006
replace evolution_score= 25 if state==40 & year<2005
replace evolution_score= 25 if state==40 & year>=2005
replace evolution_score= 82 if state==41 & year<2009
replace evolution_score= 82 if state==41 & year>=2009
replace evolution_score= 91 if state==42 & year<2002
replace evolution_score= 96 if state==42 & year>=2002
replace evolution_score= 100 if state==44 & year<2006
replace evolution_score= 82 if state==44 & year>=2006
replace evolution_score= 95 if state==45 & year<2005
replace evolution_score= 91 if state==45 & year>=2005
replace evolution_score= 82 if state==46 & year<2005
replace evolution_score= 77 if state==46 & year>=2005
replace evolution_score= 2 if state==47 & year<2007
replace evolution_score= 55 if state==47 & year>=2007
replace evolution_score= 64 if state==48 & year<2009
replace evolution_score= 46 if state==48 & year>=2009
replace evolution_score= 82 if state==49 & year<2003
replace evolution_score= 82 if state==49 & year>=2003
replace evolution_score= 86 if state==50 & year<2000
replace evolution_score= 86 if state==50 & year>=2000
replace evolution_score= 50 if state==51 & year<2003
replace evolution_score= 68 if state==51 & year>=2003
replace evolution_score= 86 if state==53 & year<2005
replace evolution_score= 86 if state==53 & year>=2005
replace evolution_score= 2 if state==54 & year<2008
replace evolution_score= 46 if state==54 & year>=2008
replace evolution_score= 55 if state==55 
replace evolution_score= 36 if state==56 & year<2003
replace evolution_score= 61 if state==56 & year>=2003
gen evo_score=evolution_score/100
label variable evo_score "Evolution Score"

***save data

save "${path}\data\googletrends\googletrends_ready.dta", replace


